#!/usr/bin/env python
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: __str__.py
# Description: 
#   類別 (class) 預設的 __str__() 方法 (method) 回傳實體 (instance) 物件 
#   (object) 的字串 (string) 表達形式
#   
#   類似:
#       java: toString()的方法
# Edit History: 
#   2011-08-10    File created.
#===============================================================================
a = 22 #1
print(a, a.__str__())
print(type(a.__str__()))
print
 
a = 22.0 #2
print(a, a.__str__())
print(type(a.__str__()))
print
 
a = "22" #3
print(a, a.__str__())
print(type(a.__str__()))
print
 
a = [22] #4
print(a, a.__str__())
print(type(a.__str__()))
print

class Demo:
    def __init__(self, i):
        self.i = i
     
    def __str__(self):
        return str(self.i)

    def hello(self):
        print("hello", self.i)
 
a = Demo(1122)
a.hello()
print
print(a, a.__str__())
print a, a.__str__()
